package com.xjj.service.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.xjj.entity.Leave;
import com.xjj.entity.PageBean;
import com.xjj.entity.ResponseEntity;
import com.xjj.service.service.LeaveService;
import com.xjj.vo.LeaveVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author : 王泰元
 * @date : 2022/10/24 17:17
 */
@Api(tags = "后台请假相关接口")
@RestController
@RequestMapping("/leave/admin")
public class AdminLeaveController {
    @Autowired
    LeaveService leaveService;

    @ApiOperation("请假列表")
    @PostMapping("/list")
    public ResponseEntity<PageBean<Leave>> list(@RequestBody LeaveVO leaveVo) {

        return ResponseEntity.SUCCESS("ok", leaveService.getByPage(leaveVo));
    }

    @ApiOperation("请假审批")
    @PostMapping("/auth")
    public ResponseEntity<String> authLeave(@RequestBody Leave leave, HttpServletRequest request) throws JsonProcessingException {
        String token = request.getHeader("token");

        leaveService.authLeave(leave,token);
        return ResponseEntity.SUCCESS("ok", null);
    }
}
